clear all 
set more off

global root "ENTER ROOT FOLDER HERE"
global output "$root/Tables/"
cd "$root"

use "Data/Analysis/nps.dta"

*** Merge in treatment assignment and district-level datasets

ren b_district dcode
merge m:1 dcode using "Data/District-level/treatment_map.dta", gen(merge_treatment_map) // Merges in treatment assignment + admin units from 1967 census (same as existed in 1966)
merge m:1 district_1967 using "Data/District-level/taxation.dta", gen(merge_tax) // Merges in Jensen & Mkama (1968) and Lee (1965) district-level data
merge m:1 dcode using "Data/District-level/schools.dta", gen(merge_schools) // Merges in admin data on schools existing prior to reform

sum merge_* // check correct merge - 2 admin districts not represented in the NPS data (merge_treatment_map), drop these
drop if merge_treatment_map==2
drop merge_*

gen bw=yob-1966 // used to restrict cohorts used in main analysis

encode district_1967, gen(dcode_1967)
encode region_1967, gen(rcode_1967)
encode district_1967_g, gen(dcode_1967_g) // FEs used in main analysis defined at (parent district * treatment) level

gen group = g_parent // baseline control districts specification (all districts sharing same pre-treatment parent district)
gen treat = group==1 & yob>=1966
replace treat = . if group==.
gen post = yob>=year_reform

encode dcode, gen(dcode_2012)
gen rcode = substr(dcode, 1,2)
encode rcode, gen(rcode_2012)
egen dcode_1967_y = concat(yob dcode_1967_g) // district-YOB clustering used in supplementary analyses

* alternative treatment definitions
gen treat_urban = g_urban==1 & yob>=1966 // alternative control districts specification (all urban districts in 1967) used in supplementary analyses
replace treat_urban = . if g_urban==.

gen treat_all = g_parent==1 & yob>=1966 // alternative control districts specification (all districts) used in supplementary analyses

* generate standardized district-level controls (used in supplementary analyses)
foreach var of varlist jm_* lee_* sch_* {
	egen z_`var' = std(`var') if abs(bw) <= 10 & treat!=.
}

label variable treat "\hspace{0.1cm} \textit{Reform}"

label variable group "\hspace{0.1cm} Born in treated district"
label variable post "\hspace{0.1cm} Born after reform"
label variable treat "\hspace{0.1cm} \textit{Reform}"

cd "$root"
save "Data/Analysis/nps_analysis.dta", replace // export analysis file for use in make_figures.R

global ctrl = "c.pl_male c.pl_male#(i.dcode_1967_g)"
global fe = "yob dcode_1967_g"
global clust = "dcode_1967_g"

********************************************************************************
*** Descriptive statistics (Table A2) ******************************************
********************************************************************************

cd "$output"

label variable age "\hspace{0.1cm} Age"
label variable pl_male "\hspace{0.1cm} Male"
label variable ed_parent_pri "\hspace{0.1cm} Parent has primary education"
label variable ed_parent_sec "\hspace{0.1cm} Parent has secondary education"
label variable ed_parent_uni "\hspace{0.1cm} Parent has university education"

label variable b_cert "\hspace{0.1cm} Registered"
label variable group "\hspace{0.1cm} Born in treated district"
label variable post "\hspace{0.1cm} Born after reform"

label variable tax_all "\hspace{0.1cm} Paid any tax"
label variable tax_fee "\hspace{0.1cm} Paid fees"
label variable tax_local "\hspace{0.1cm} Paid local tax"
label variable tax_central "\hspace{0.1cm} Paid central tax"

local desc_vars "age pl_male ed_parent_pri ed_parent_sec ed_parent_uni"
local fs_vars "b_cert group post treat"
local out_vars "tax_all tax_fee tax_local tax_central"

estpost summarize `desc_vars' `fs_vars' `out_vars' if abs(bw) <= 10 & group!=., listwise 
est store A
estpost summarize `desc_vars' `fs_vars' `out_vars' if abs(bw) <= 10 & group==1, listwise 
est store B
estpost summarize `desc_vars' `fs_vars' `out_vars' if abs(bw) <= 10 & group==0, listwise 
est store C

local over "& \multicolumn{2}{c}{Both} & \multicolumn{2}{c}{Treated} & \multicolumn{2}{c}{Control} \\"
local lines "\cmidrule(lr{0.5em}){2-3} \cmidrule(lr{0.5em}){4-5} \cmidrule(lr{0.5em}){6-7}"	
local names "& Mean & SD & Mean & SD & Mean & SD \\ \midrule"	
esttab A B C using "Table A2.tex", replace posthead("`over'" "`lines'" "`names'") nonum cells("mean(fmt(2) label({})) sd(fmt(2) label({}))") label nomtitles b(3) se f nogaps booktabs sfmt(3 0) compress refcat(age "\textbf{A. Sample characteristics}" b_cert "\textbf{B. First stage variables}" paid_any_all "\textbf{C. Outcome variables}", nolabel)


********************************************************************************
*** Table A4: First stage robustness *******************************************
********************************************************************************

cd "$output"

label variable treat "\hspace{0.1cm} \textit{Reform} ($\beta^{FS}$)"

local cols "fs_1_1 fs_1_2 fs_1_3 fs_2_1 fs_2_2 fs_2_3"

local t1 ""
local t2 "i.rcode_1967#c.yob"
local t3 "i.dcode_1967_g#c.yob#c.yob"
local trends1 "None"
local trends2 "Region"
local trends3 "District"

estimates clear

foreach spec in 1 2 3 {
	
	* baseline specifications (varying use of unit-linear time trends)
	eststo fs_1_`spec': quietly reghdfe b_cert treat `t`spec'' $ctrl if abs(bw) <= 10, absorb( $fe ) cluster( $clust )
		estadd local Trends "`trends`spec''"
		sum b_cert if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'	
	* unrestricted cohorts 
	eststo fs_2_`spec': quietly reghdfe b_cert treat `t`spec'' $ctrl, absorb( $fe ) cluster( $clust )
		estadd local Trends "`trends`spec''"
		sum b_cert if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'

}

local titles "\midrule & \multicolumn{3}{c}{\textbf{+/- 10 cohorts}} & \multicolumn{3}{c}{\textbf{All cohorts}} \\"
local lines "\cmidrule(lr{0.5em}){2-4} \cmidrule(lr{0.5em}){5-7} "
local numbers "\textbf{F. National Panel Survey dataset} & (1) & (2) & (3) & (4) & (5) & (6) \\ \midrule"
esttab `cols' using "Table A4.tex", nonumber append posthead("`titles'" "`lines'" "`numbers'") nomtitles b(2) se label f nogaps booktabs scalars("Trends Time trends" "DV_Mean Outcome mean" "N Observations") sfmt(3 2 0) noobs compress star(* 0.10 ** 0.05 *** 0.01) nobaselevels keep(treat)
esttab `cols' using "With controls/Table A4.tex", nonumber append posthead("`titles'" "`lines'" "`numbers'") nomtitles b(2) se label f nogaps booktabs scalars("Trends Time trends" "DV_Mean Outcome mean" "N Observations") sfmt(3 2 0) noobs compress star(* 0.10 ** 0.05 *** 0.01) nobaselevels keep(treat pl_*)


********************************************************************************
*** IV results (Table 3) *******************************************************
********************************************************************************

estimates clear

local tax_vars "tax_all tax_fee tax_local tax_central"

foreach var in  `tax_vars' {
	capture drop z_`var'
	egen z_`var' = std(`var')
}

foreach var in tax_all tax_fee tax_local tax_central {

	eststo `var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10 & group!=., absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob if abs(bw)<=10 & group!=., a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define pmat = J(1,2,0)
		matrix pmat[1,2] = 2*ttail(e(df_r),abs(_b[pl_male]/_se[pl_male]))
		matrix colnames pmat = b_cert pl_male
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix pmat[1,1] = `r(p)'
		estadd matrix pboot = pmat
		est sto `var'_iv
	eststo z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & group!=., absorb( $fe ) cluster( $clust ) // rho vector		
		
	eststo `var'_all: quietly reghdfe `var' b_cert $ctrl if group!=., absorb( $fe ) cluster( $clust )
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob , a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define pmat = J(1,2,0)
		matrix pmat[1,2] = 2*ttail(e(df_r),abs(_b[pl_male]/_se[pl_male]))
		matrix colnames pmat = b_cert pl_male
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix pmat[1,1] = `r(p)'
		estadd matrix pboot = pmat
		est sto `var'_iv_all
	eststo z_`var'_all: quietly reghdfe z_`var' z_asset_pca $ctrl if group!=., absorb( $fe ) cluster( $clust ) // rho vector		
	
}

cd "$output"

*** Table 3: Effects on exposure to taxation
********************************************************************************

local names "& All & Fees & Local & Central \\"
local lines " \cmidrule(lr{0.5em}){3-5} "
local numbers " & (1) & (2) & (3) & (4) \\ \midrule"

esttab tax_all tax_fee tax_local tax_central using "Table 3.tex",  coeflabel(b_cert "\hspace{0.1cm} Registered ($\beta^{OLS})$") replace posthead("`names'" "`lines'" "`numbers'") nonumber nomtitles b(2) se label f nogaps booktabs sfmt(0) noobs compress nobaselevels keep(b_*) star(* 0.10 ** 0.05 *** 0.01)
esttab tax_all_iv tax_fee_iv tax_local_iv tax_central_iv using "Table 3.tex", append cells(b(star pvalue(pboot) fmt(%9.2f)) se(par fmt(%9.2f)) pboot(par([ ]) fmt(%9.2f))) coeflabel(b_cert  "\hspace{0.1cm} $\widehat{\text{Registered}}$ ($\beta^{IV})$") nonumber nomtitles label f nogaps booktabs noobs stats(DV_Mean widstat, labels("\midrule DV Mean" "FS F-statistic") layout("@") fmt(2 1)) compress nobaselevels keep(b_cert) nolines prehead(\midrule) star(* 0.10 ** 0.05 *** 0.01) mlabels(,none) collabels(,none)
esttab z_tax_all z_tax_fee z_tax_local z_tax_central using "Table 3.tex", coeflabel(z_asset_pca "\$\rho\$(Wealth, DV)")	append nonumber nomtitles b(2) not label f nogaps booktabs sfmt(0) noobs scalars("N Observations") compress nostar nobaselevels keep(z_asset_pca)

esttab tax_all_all tax_fee_all tax_local_all tax_central_all using "Table A10.tex",  coeflabel(b_cert "\hspace{0.1cm} Registered ($\beta^{OLS})$") replace posthead("`names'" "`lines'" "`numbers'") nonumber nomtitles b(2) se label f nogaps booktabs sfmt(0) noobs compress nobaselevels keep(b_*) star(* 0.10 ** 0.05 *** 0.01)
esttab tax_all_iv_all tax_fee_iv_all tax_local_iv_all tax_central_iv_all using "Table A10.tex", append cells(b(star pvalue(pboot) fmt(%9.2f)) se(par fmt(%9.2f)) pboot(par([ ]) fmt(%9.2f))) coeflabel(b_cert  "\hspace{0.1cm} $\widehat{\text{Registered}}$ ($\beta^{IV})$") nonumber nomtitles label f nogaps booktabs noobs stats(DV_Mean widstat, labels("\midrule DV Mean" "FS F-statistic") layout("@") fmt(2 1)) compress nobaselevels keep(b_cert) nolines prehead(\midrule) star(* 0.10 ** 0.05 *** 0.01) mlabels(,none) collabels(,none)
esttab z_tax_all_all z_tax_fee_all z_tax_local_all z_tax_central_all using "Table A10.tex", coeflabel(z_asset_pca "\$\rho\$(Wealth, DV)") append nonumber nomtitles b(2) not label f nogaps booktabs sfmt(0) noobs scalars("N Observations") compress nostar nobaselevels keep(z_asset_pca)

* Including all control coefficients
esttab tax_all tax_fee tax_local tax_central using "With controls/Table 3.tex",  coeflabel(b_cert "\hspace{0.1cm} Registered ($\beta^{OLS})$") replace posthead("`names'" "`lines'" "`numbers'") nonumber nomtitles b(2) se label f nogaps booktabs sfmt(0) noobs compress nobaselevels keep(pl_male b_*) order(pl_male b_* ) star(* 0.10 ** 0.05 *** 0.01)
esttab tax_all_iv tax_fee_iv tax_local_iv tax_central_iv using "With controls/Table 3.tex", cells(b(star pvalue(pboot) fmt(%9.2f)) se(par fmt(%9.2f)) pboot(par([ ]) fmt(%9.2f))) coeflabel(b_cert "\hspace{0.1cm} $\widehat{\text{Registered}}$ ($\beta^{IV})$") append nonumber nomtitles label f nogaps booktabs noobs stats(DV_Mean widstat, labels("\midrule DV Mean" "FS F-statistic") layout("@") fmt(2 1)) compress nobaselevels keep(pl_male b_cert) order(pl_* b_cert) nolines prehead(\midrule) star(* 0.10 ** 0.05 *** 0.01) mlabels(,none) collabels(,none)
esttab z_tax_all z_tax_fee z_tax_local z_tax_central using "With controls/Table 3.tex", coeflabel(z_asset_pca "\$\rho\$(Wealth, DV)")	append nonumber nomtitles b(2) not label f nogaps booktabs sfmt(0) noobs scalars("N Observations") compress nostar nobaselevels keep(z_asset_pca)

esttab tax_all_all tax_fee_all tax_local_all tax_central_all using "With controls/Table A10.tex",  coeflabel(b_cert "\hspace{0.1cm} Registered ($\beta^{OLS})$") replace posthead("`names'" "`lines'" "`numbers'") nonumber nomtitles b(2) se label f nogaps booktabs sfmt(0) noobs compress nobaselevels keep(b_* pl_*) order(pl_male b_* ) star(* 0.10 ** 0.05 *** 0.01)
esttab tax_all_iv_all tax_fee_iv_all tax_local_iv_all tax_central_iv_all using "With controls/Table A10.tex", cells(b(star pvalue(pboot) fmt(%9.2f)) se(par fmt(%9.2f)) pboot(par([ ]) fmt(%9.2f))) coeflabel(b_cert "\hspace{0.1cm} $\widehat{\text{Registered}}$ ($\beta^{IV})$") append nonumber nomtitles label f nogaps booktabs noobs stats(DV_Mean widstat, labels("\midrule DV Mean" "FS F-statistic") layout("@") fmt(2 1)) compress nobaselevels keep(pl_male b_cert) order(pl_* b_cert) nolines prehead(\midrule) star(* 0.10 ** 0.05 *** 0.01) mlabels(,none) collabels(,none)
esttab z_tax_all_all z_tax_fee_all z_tax_local_all z_tax_central_all using "With controls/Table A10.tex", coeflabel(z_asset_pca "\$\rho\$(Wealth, DV)") append nonumber nomtitles b(2) not label f nogaps booktabs sfmt(0) noobs scalars("N Observations") compress nostar nobaselevels keep(z_asset_pca)



*** Table 3 using every estimating permutation from Table A4 
********************************************************************************

foreach var in tax_all tax_fee tax_local tax_central {

	eststo A_1_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=5 & group!=., absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob if abs(bw)<=5 & group!=., a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto A_1_`var'_iv
	eststo A_1_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=5 & group!=., absorb( $fe ) cluster( $clust )
		
	eststo A_2_`var': quietly reghdfe `var' b_cert $ctrl if group!=., absorb( $fe ) cluster( $clust )
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob , a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1 
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto A_2_`var'_iv
	eststo A_2_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if group!=., absorb( $fe ) cluster( $clust )
	
	eststo B_1_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10 & group!=. & yob!=1966, absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob  if abs(bw)<=10 & group!=. & yob!=1966, a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto B_1_`var'_iv
	eststo B_1_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & group!=. & yob!=1966, absorb( $fe ) cluster( $clust )
		
	eststo B_2_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10 & group!=. & age!=40&age!=45&age!=50&age!=55, absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob  if abs(bw)<=10 & group!=. & age!=40&age!=45&age!=50&age!=55, a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto B_2_`var'_iv
	eststo B_2_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & group!=. & age!=40&age!=45&age!=50&age!=55, absorb( $fe ) cluster( $clust )
		
	local distvars "c.z_jm_* c.z_lee_* c.z_sch_*"	
	eststo C_1_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10 & group!=., absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob  c.post#(`distvars') if abs(bw)<=10 & group!=., a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto C_1_`var'_iv
	eststo C_1_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & group!=., absorb( $fe ) cluster( $clust )
	
	local indvars "c.pl_* i.dcode_1967_g#(c.pl_*)"
	eststo C_2_`var': quietly reghdfe `var' b_cert `indvars' if abs(bw)<=10 & group!=., absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat) pl_male i.yob `indvars' if abs(bw)<=10 & group!=., a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto C_2_`var'_iv
	eststo C_2_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & group!=., absorb( $fe ) cluster( $clust )
	
	cap drop treat_1
	gen treat_1 = treat_urban
	label variable treat_1 "\hspace{0.1cm} \textit{Reform}"	
	eststo D_1_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10 & g_urban!=., absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat_1) $ctrl i.yob if abs(bw)<=10 & g_urban!=., a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto D_1_`var'_iv
	eststo D_1_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & g_urban!=., absorb( $fe ) cluster( $clust )
		
	cap drop treat_1
	gen treat_1 = treat_all
	label variable treat_1 "\hspace{0.1cm} \textit{Reform}"	
	eststo D_2_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10, absorb( $fe ) cluster( $clust )	
	quietly ivreghdfe `var' (b_cert=treat_1) $ctrl i.yob if abs(bw)<=10, a( $clust ) cluster( $clust )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto D_2_`var'_iv
	eststo D_2_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10, absorb( $fe ) cluster( $clust )
		
	eststo E_1_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10 & group!=., absorb( dcode_2012 yob ) cluster( dcode_2012 )	
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob if abs(bw)<=10 & group!=., a( dcode_2012 ) cluster( dcode_2012 )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto E_1_`var'_iv
	eststo E_1_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & group!=., absorb( dcode_2012 yob ) cluster( dcode_2012 )
		
	eststo E_2_`var': quietly reghdfe `var' b_cert $ctrl if abs(bw)<=10 & group!=., absorb( $fe ) cluster( dcode_1967_y )	
	quietly ivreghdfe `var' (b_cert=treat) $ctrl i.yob if abs(bw)<=10 & group!=., a( $clust ) cluster( dcode_1967_y )	
		sum `var' if e(sample)==1
		estadd scalar DV_Mean = `r(mean)'
		matrix define bpmat = J(1,1,0)
		matrix colnames bpmat = "b_cert"
		boottest b_cert, reps(5000) seed(94305) noci statistic(t)
		matrix bpmat[1,1] = `r(p)'
		estadd matrix pboot = bpmat
		est sto E_2_`var'_iv
	eststo E_2_z_`var': quietly reghdfe z_`var' z_asset_pca $ctrl if abs(bw)<=10 & group!=., absorb( $fe ) cluster( dcode_1967_y )
}

foreach spec in A B C D E {
	
	foreach v in 1 2 {
		
		local names "& All & Fees & Local & Central \\"
		local lines " \cmidrule(lr{0.5em}){3-5} "
		local numbers " & (1) & (2) & (3) & (4) \\ \midrule"
		
		esttab `spec'_`v'_tax_all `spec'_`v'_tax_fee `spec'_`v'_tax_local `spec'_`v'_tax_central using "Additional results/Table 3_`spec'`v'.tex", /// 
			coeflabel(b_cert "\hspace{0.1cm} Registered ($\beta^{OLS})$") replace nonumber posthead("`names'" "`lines'" "`numbers'") nomtitles b(2) se label f nogaps booktabs sfmt(0) /// 
			noobs compress nobaselevels keep(b_cert) star(* 0.10 ** 0.05 *** 0.01)
		esttab `spec'_`v'_tax_all_iv `spec'_`v'_tax_fee_iv `spec'_`v'_tax_local_iv `spec'_`v'_tax_central_iv using "Additional results/Table 3_`spec'`v'.tex", append cells(b(star pvalue(pboot) fmt(%9.2f)) se(par fmt(%9.2f)) pboot(par([ ]) fmt(%9.2f))) coeflabel(b_cert  "\hspace{0.1cm} $\widehat{\text{Registered}}$ ($\beta^{IV})$") nonumber nomtitles label f nogaps booktabs noobs stats(DV_Mean widstat, labels("\midrule DV Mean" "FS F-statistic") layout("@") fmt(2 1)) compress nobaselevels keep(b_cert) nolines prehead(\midrule) star(* 0.10 ** 0.05 *** 0.01) mlabels(,none) collabels(,none)
		esttab `spec'_`v'_z_tax_all `spec'_`v'_z_tax_fee `spec'_`v'_z_tax_local `spec'_`v'_z_tax_central using "Additional results/Table 3_`spec'`v'.tex", /// 
			coeflabel(z_asset_pca "\$\rho\$(Wealth, DV)") append nonumber nomtitles b(2) not label f nogaps booktabs sfmt(0) noobs scalars("N Observations") compress nostar nobaselevels keep(z_asset_pca)

	}
}


********************************************************************************
*** Complier characteristics (Table 5) *****************************************
********************************************************************************

*** See make_figures.R ***

